﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using FineUI;
using ZHDJ.Data.Models.Center;
using ZHDJ.Data.Models.Org;
using ZHDJ.PersonalCenter.BLL;
using ZHDJ.WebPage;
using Panel = System.Web.UI.WebControls.Panel;
using TextBox = System.Web.UI.WebControls.TextBox;

namespace ZHDJ.PersonalCenter.Module.MembersFindOrg
{
    public partial class MembersFindOrgEdit : PageBase
    {
        #region ViewPower

        /// <summary>
        /// 本页面的浏览权限，空字符串表示本页面不受权限控制
        /// </summary>
        public override string ViewPower
        {
            get
            {
                return "";
            }
        }
        #endregion

        #region Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            btnClose.OnClientClick = ActiveWindow.GetHideReference();
            string id = GetQueryIntValue("id");
            if (id != "")
            {
                PartyMembersFindOrg findOrg = DB.PartyMembersFindOrgs.Find(id);
                if (findOrg == null)
                {
                    // 参数错误，首先弹出Alert对话框然后关闭弹出窗口
                    Alert.Show("参数错误！", String.Empty, ActiveWindow.GetHideReference());
                    return;
                }

                Panel Panel2 = SimpleForm1.FindControl("Panel2") as Panel;
                TextBox txtUserName = Panel2.FindControl("txtUserName") as TextBox;
                TextBox txtGender = Panel2.FindControl("txtGender") as TextBox;
                TextBox txtBirthday = Panel2.FindControl("txtBirthday") as TextBox;
                TextBox txtAge = Panel2.FindControl("txtAge") as TextBox;
                TextBox txtQQNumber = Panel2.FindControl("txtQQNumber") as TextBox;
                TextBox txtEducational = Panel2.FindControl("txtEducational") as TextBox;
                TextBox txtNativePlace = Panel2.FindControl("txtNativePlace") as TextBox;
                TextBox txtNation = Panel2.FindControl("txtNation") as TextBox;
                TextBox txtPost = Panel2.FindControl("txtPost") as TextBox;
                TextBox txtJoinPartyDate = Panel2.FindControl("txtJoinPartyDate") as TextBox;
                TextBox txtPartyJobAddress = Panel2.FindControl("txtPartyJobAddress") as TextBox;
                TextBox txtPartyCard = Panel2.FindControl("txtPartyCard") as TextBox;
                TextBox txtMobileNo = Panel2.FindControl("txtMobileNo") as TextBox;
                TextBox txtCreateTime = Panel2.FindControl("txtCreateTime") as TextBox;
                TextBox txtAddress = Panel2.FindControl("txtAddress") as TextBox;
                TextBox txtBranchName = Panel2.FindControl("txtBranchName") as TextBox;
                TextArea txtRemark = Panel2.FindControl("txtRemark") as TextArea;

                txtUserName.Text = findOrg.UserName;
                txtGender.Text = findOrg.Gender == "0" ? "男" : "女";
                txtBirthday.Text = findOrg.Birthday;
                if (!string.IsNullOrEmpty(findOrg.Birthday))
                {
                    int age = DateTime.Now.Year - Convert.ToDateTime(findOrg.Birthday).Year;
                    txtAge.Text = age.ToString();
                }
                txtQQNumber.Text = findOrg.QQNumber;
                txtEducational.Text = findOrg.Educational;
                txtNativePlace.Text = findOrg.NativePlace;
                txtNation.Text = findOrg.Nation;
                txtPost.Text = findOrg.Post;
                if (findOrg.JoinPartyDate != null)
                {
                    txtJoinPartyDate.Text = Convert.ToDateTime(findOrg.JoinPartyDate).ToString("yyyy-MM-dd");
                }
                txtPartyJobAddress.Text = findOrg.PartyJobAddress;
                txtPartyCard.Text = findOrg.PartyCard;
                txtMobileNo.Text = findOrg.MobileNo;
                txtCreateTime.Text = Convert.ToDateTime(findOrg.CreateTime).ToString("yyyy-MM-dd HH:mm");
                txtAddress.Text = findOrg.Address;
                txtBranchName.Text = ControlBusiness.GetBranchPickerText(findOrg.BranchID);
                txtRemark.Text = findOrg.Remark;

                if (findOrg.Status != "1")
                {
                    
                }
            }
        }
        #endregion

        #region Events

        private void SaveData(bool isAgree)
        {
           
            
        }

        /// <summary>
        /// 同意按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAgree_Click(object sender, EventArgs e)
        {
            SaveData(true);

            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }

        /// <summary>
        /// 不同意按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnNotAgree_Click(object sender, EventArgs e)
        {
            SaveData(false);

            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }
        #endregion
    }
}